//questo plug utilizza il preload di farinspace definito in plugin.js

//definizioni e proprieta
$.SLIDES = new Object();
$.SLIDES.active = true;
$.SLIDES.thumbContaninerClass = 'thumbs';
$.SLIDES.thumbWrapperClass = 'thumbWrap';
$.SLIDES.thumbSelector = '.thumbs .thumbWrap .singleThumb';
$.SLIDES.firstThumb = $('.thumbs .thumbWrap div:first');
$.SLIDES.maxThumbWidth = 150;
$.SLIDES.maxThumbPadding = 3;
$.SLIDES.maxThumbBorder = 1;

$.SLIDES.slideContaninerClass = 'slides';
$.SLIDES.slideWrapperClass = 'pics';
$.SLIDES.slideSelector = '.slides .pics .singlePic';
$.SLIDES.slideSelectorLast = '.slides .pics .singlePic.allRight';
$.SLIDES.slideCode = '<div class="singlePic allRight"><div class="theImg"><img src="" alt="" style="width:100%; height:auto;" class="slideCurrentImage" /><div class="navigation"><div class="label fontLektonBold current" data-id=""><span></span></div><div class="label fontLektonBold next stdHover" data-id=""><span></span></div></div></div></div>';


$.SLIDES.thumbCount = 0;
$.SLIDES.slideCounter = 0;
$.SLIDES.currentSlideCounter = 0;

$.SLIDES.liveTimer = true;
$.SLIDES.timer = 0;
$.SLIDES.timerCounter = 0;
$.SLIDES.maxMillisecondi = 0;

$.SLIDES.thumbUpLimit = 0;//

$.SLIDES.navigationActiveHover = true;

$.SLIDES.startingLoadElementsCount = 0;

$.SLIDES.startingLoadElementsBase = 'img/';
//LOGOS
//$.SLIDES.startingLoadElements =  ['logo.png','logob.png','logow.png','logor.png','logo-slide2.png','logo-slide3.png','logo-slide4.png','logo-slide5.png','logo-slide6.png','logo-slide7.png','logo-slide8.png','logo-slide9.png','logo-slide10.png'];
//BG
//$.SLIDES.startingLoadElements.push('bg.jpg');
//MENU
/*$.SLIDES.startingLoadElements.push('menu1.jpg');
 $.SLIDES.startingLoadElements.push('menu2.jpg');
 $.SLIDES.startingLoadElements.push('menu3.jpg');
 $.SLIDES.startingLoadElements.push('stickMask1.png');
 $.SLIDES.startingLoadElements.push('stickMask3.png');
 $.SLIDES.startingLoadElements.push('stickMask2.png');
 $.SLIDES.startingLoadElements.push('up.png');
 $.SLIDES.startingLoadElements.push('down.png');
 $.SLIDES.startingLoadElements.push('sick-bg.png');*/
$.SLIDES.paramNav = true;


//metodi
$.SLIDES.countSlides = function () {
    $.SLIDES.thumbCount = ($($.SLIDES.thumbSelector).size());
    return $.SLIDES.thumbCount;
}

$.SLIDES.resizeThumbContainer = function () {
}

$.SLIDES.resizeThumb = function () {
}

$.SLIDES.openThumb = function () {
}

$.SLIDES.closeThumb = function () {
}

$.SLIDES.setSlideCounter = function (intSlideCounter) {
    (intSlideCounter) ? $.SLIDES.slideCounter = intSlideCounter : $.SLIDES.slideCounter = 0;
}

$.SLIDES.getSlideCounter = function () {
    return $.SLIDES.slideCounter;
}

$.SLIDES.nextSlideCounter = function () {
    ($.SLIDES.thumbCounter < $.SLIDES.getSlideCounter()) ? $.SLIDES.thumbCounter++ : $.SLIDES.thumbCounter = 0;
    $.SLIDES.getSlideCounter();
}

$.SLIDES.prevSlideCounter = function () {
    ($.SLIDES.thumbCounter >= 0) ? $.SLIDES.thumbCounter-- : $.SLIDES.thumbCounter = $.SLIDES.countSlides();
    $.SLIDES.getSlideCounter();
}

$.SLIDES.clearSlides = function () {
    $($.SLIDES.slideSelector).remove();
}

$.SLIDES.isSlideLoad = function (intSlideCounter) {
    if ($('.singleThumb[data-id="' + intSlideCounter + '"]').attr('data-loaded') == 'true') return true;
    return false;
}

$.SLIDES.newSlide = function (intSlideCounter) {

    $.SLIDES.moveTimeLine(intSlideCounter);

    $.SLIDES.active = !$.SLIDES.active;
    var tempCounter = 0;
    var elementsArray = $('.thumbs .thumbWrap .singleThumb').toArray();

    $.SLIDES.initSound('slideSound', $(elementsArray[intSlideCounter]).attr('data-audio'));
    $.SLIDES.initSound('bgSound', $(elementsArray[intSlideCounter]).attr('data-audio_bg'));

    if (/*intSlideCounter != 'home'*/!$.SLIDES.isLast(intSlideCounter)) {

        $('.' + $.SLIDES.slideWrapperClass).append($.SLIDES.slideCode);

        var currentBgImg = $(elementsArray[intSlideCounter]).attr('data-full');
        var currentDataColor = $(elementsArray[intSlideCounter]).attr('data-color');
        var currentHeading = $(elementsArray[intSlideCounter]).attr('data-heading');
        var currentContent = $(elementsArray[intSlideCounter]).attr('data-content');


        /*$($.SLIDES.slideSelectorLast).find('.theImg').css({backgroundImage:'url('+currentBgImg+')'});Setto bg*/
        $($.SLIDES.slideSelectorLast).find('.theImg .slideCurrentImage').attr('src', currentBgImg);
        $.SLIDES.initTopMargin();

        $($.SLIDES.slideSelectorLast).find('.label').stop().animate({opacity: .5}, 'slow');

        //definisco i valori label e data id nel navigation
        var labCount = $.SLIDES.countSlides() - (parseInt(intSlideCounter) + 1);
        $($.SLIDES.slideSelectorLast).find('.label.current span').html(UTILS.dueCifre(labCount));
        $($.SLIDES.slideSelectorLast).find('.label.current').attr('data-id', parseInt(intSlideCounter));
        labCount = $.SLIDES.countSlides() - (parseInt(intSlideCounter) + 2);
        $($.SLIDES.slideSelectorLast).find('.label.next span').html(UTILS.dueCifre(labCount));
        $($.SLIDES.slideSelectorLast).find('.label.next').attr('data-id', (parseInt(intSlideCounter) + 1));
        //verifico se è ultimo
        //$.UTILS.outVariable('call for:'+parseInt(parseInt(intSlideCounter)+1)+' is it last:'+$.SLIDES.isLast(parseInt(parseInt(intSlideCounter)+1)));

        if ($.SLIDES.isLast(parseInt(parseInt(intSlideCounter) + 1))) {
            $($.SLIDES.slideSelectorLast).find('.label.next span').html('&nbsp;');
            //$($.SLIDES.slideSelectorLast).find('.label.next').css({'background-image': 'url(img/next.gif)'});
            $($.SLIDES.slideSelectorLast).find('.label.next').addClass('last');
        }
        TweenLite.to($($.SLIDES.slideSelectorLast).find('.navigation'), 1, {css: {right: '-108px'}, delay: 1.8});
        $.SLIDES.initTopMargin();
        TweenLite.to($($.SLIDES.slideSelectorLast), 1, {css: {left: "0%"}, delay: 1.5, ease: Sine.easeOut, onComplete: $.SLIDES.killLastSlide});
        $.SLIDES.initTopMargin();
        $.SLIDES.mostraCaption(intSlideCounter);
        $.SLIDES.currentSlideCounter = intSlideCounter;
        $.COLOR.addColorClass(currentDataColor);
        //reset menu
        $('.thumbs .thumbWrap .singleThumb.current').removeClass('current');
        //var tl = new TimelineLite({delay:0});
        //tl.to($('#singleThumb_'+intSlideCounter), .3, {css:{marginTop:'0px'}, ease:Expo.easeOut});
        //tl.to($('#singleThumb_'+intSlideCounter), .5, {css:{marginTop:'0px'}, ease:Expo.easeOut});
        //tl.to($('#singleThumb_'+intSlideCounter), .3, {css:{marginTop:(0-($('#singleThumb_'+intSlideCounter).height()-$.SLIDES.thumbUpLimit))+'px'}, ease:Expo.easeOut});
        $('#singleThumb_' + intSlideCounter).addClass('current');
        if (intSlideCounter == '9') {
            $('.stdHover.last span').text('10');
        }
        /*$('.slideshow-txt').fadeOut(function(){
         $('.slideshow-txt-lbl').text(currentHeading);
         $('.slideshow-txt-p').text(currentContent);
         $('.slideshow-txt').delay(1970).fadeIn();
         });
         */
    } else {
        $.SLIDES.gotoHome('back');
    }
}


$.SLIDES.isLast = function (intSlideCounter) {
    if ((parseInt(intSlideCounter) + 1) >= $.SLIDES.countSlides()) {
        return true;
    }
    return false;
}

$.SLIDES.killLastSlide = function () {


    //SHOW LOGO
    TweenLite.to($('header'), .5, {css: {height: '230px'}, ease: Sine.easeOut});

    $.SLIDES.navigationActiveHover = true;
    var $this = $($.SLIDES.slideSelectorLast);
    $this.prev().remove();
    $this.removeClass('allRight');
    $.SLIDES.active = !$.SLIDES.active;
}

$.SLIDES.loadThumbs = function () {

    if ($.SLIDES.firstThumb.exists()) {

        var t = (new Date).getTime();
        var the_images = [];
        var thumbImgUrl = $.SLIDES.firstThumb.attr('data-thumb');
        var fullImgUrl = $.SLIDES.firstThumb.attr('data-full');
        var fullImgUrlHome = $.SLIDES.firstThumb.attr('data-full-home');
        var thumbImgIndex = $.SLIDES.firstThumb.attr('data-id');
        the_images.push(fullImgUrl);
        the_images.push(thumbImgUrl);
        if (fullImgUrlHome) {
            var runPreLoad = fullImgUrlHome.split(",");
            for (var i = 0; i < runPreLoad.length; i++) {
                the_images.push(runPreLoad[i]);
            }

        }
        jQuery.imgpreload(the_images, {each: function () {
            //UTILS.varDump($(this));
            if (0 == parseInt(thumbImgIndex)) {
                $.SLIDES.startingLoadElementsCount++;
                var nuWidth = 100 / the_images.length * $.SLIDES.startingLoadElementsCount;
                TweenLite.to($('#preload .animated'), .3, {css: {width: nuWidth + '%'}, ease: Expo.easeOut});
            }
        }, all: function () {

            //$.SLIDES.firstThumb.css({marginTop:'-1000px'});
            if (!$.SLIDES.isLast(thumbImgIndex)) {

                $.SLIDES.firstThumb.attr('data-loaded', 'true');
                //TweenLite.to($.SLIDES.firstThumb, .3, {css:{marginTop:(0-($.SLIDES.firstThumb.height()-$.SLIDES.thumbUpLimit))+'px'}, ease:Expo.easeOut});
                $.SLIDES.firstThumb = $.SLIDES.firstThumb.next();
                if (0 == parseInt(thumbImgIndex)) {
                    $.SLIDES.newSlide(0);
                    $.SLIDES.preInit();
                }
                $.SLIDES.loadThumbs();

            } else {
                $.SLIDES.init();
            }
            the_images = [];
        }});
    } else {
        $.SLIDES.init();
    }
}


$.SLIDES.resizeThumbWrap = function () {

}
/*
 $.SLIDES.resizeThumbs = function(){
 $('.thumbs').animate({top:'-400px'},500,function(){
 var windowW = $(window).width();
 var singleThumbW = Math.round(windowW/($.SLIDES.countSlides()-1));
 $('.thumbs .thumbWrap').css({width:(($.SLIDES.countSlides()-1)*singleThumbW)+'px'});
 singleThumbW = singleThumbW-3;
 $('.thumbs .thumbWrap .singleThumb').css({'width':singleThumbW+'px', marginTop:'0px'});
 $('.thumbs .thumbWrap .singleThumb').each(function(){
 TweenLite.to($(this), 0, {css:{marginTop:(0-($(this).height()-$.SLIDES.thumbUpLimit))+'px'}, ease:Expo.easeOut});
 });
 $('.thumbs').delay(500).animate({top:'0px'},500,function(){
 $('.thumbs .thumbWrap .singleThumb').each(function(){
 TweenLite.to($(this), .5, {css:{marginTop:(0-($(this).height()-$.SLIDES.thumbUpLimit))+'px'}, ease:Expo.easeOut});
 });
 });
 });

 $('.explorer .thumbWrap').show();
 }*/

$.SLIDES.resizeThumbs = function () {
    $('.thumbs').css({display: 'none'});

    var windowW = $(window).width();
    var singleThumbW = windowW / ($.SLIDES.countSlides() - 1);
    $('.thumbs .thumbWrap .singleThumb').css({'width': singleThumbW + 'px', marginTop: '0px'});
    $('.thumbs .thumbWrap .singleThumb').each(function () {
        //TweenLite.to($(this), 0, {css:{marginTop:(0-($(this).height()-$.SLIDES.thumbUpLimit))+'px'}, ease:Expo.easeOut});
    });
    $('.thumbs').delay(500).animate({top: '-120px'}, 500, function () {
        $('.thumbs .thumbWrap .singleThumb').each(function () {
            //TweenLite.to($(this), .5, {css:{marginTop:(0-($(this).height()-$.SLIDES.thumbUpLimit))+'px'}, ease:Expo.easeOut});
        });
    });
    $('.thumbs').css({display: 'block'});
    $('.thumbs .thumbWrap .singleThumb').css({marginTop: '0px'});
    $('.explorer .thumbWrap').show();
}

$.SLIDES.nascondiCaption = function () {
    //TweenLite.to($('.caption'), 0, {css:{opacity:0}, ease:Expo.easeOut, onComplete: function(){$('.caption').css({display:'none'});}});
    TweenLite.to($('.caption'), 0, {css: {height: '0px'}, ease: Sine.easeOut, onComplete: function () {
        $('.caption').css({display: 'none'});
    }});
}

$.SLIDES.mostraCaption = function (intSlideCounter) {
    $.SLIDES.nascondiCaption();

    //caption standard
    $.SLIDES.captionResize();
    $('.caption[data-id="' + intSlideCounter + '"]').css({display: 'block'});
    /*TweenLite.to($('.caption[data-id="'+intSlideCounter+'"]'), .5, {css:{opacity:1}, ease:Expo.easeInOut, onComplete:function(){
     TweenLite.to($('.caption[data-id="'+intSlideCounter+'"]'), .5, {css:{opacity:0}, delay:6, ease:Expo.easeOut});
     }});*/

    TweenLite.to($('.caption[data-id="' + intSlideCounter + '"]'), .5, {css: {height: '270px'}, delay: 3, ease: Expo.easeInOut, onComplete: function () {
        TweenLite.to($('.caption[data-id="' + intSlideCounter + '"]'), .5, {css: {height: '0px'}, delay: 6, ease: Expo.easeOut});
    }});


}
$.SLIDES.aggiornaCaption = function () {
}


$.SLIDES.newSlideHome = function (intSlideCounter, mode) {

    $.SLIDES.moveTimeLine(intSlideCounter);

    var elementsArray = $('.thumbs .thumbWrap .singleThumb').toArray();
    var currentBgImg = $(elementsArray[intSlideCounter]).attr('data-full');
    var currentDataColor = $(elementsArray[intSlideCounter]).attr('data-color');

    $.SLIDES.initSound('slideSound', $(elementsArray[intSlideCounter]).attr('data-audio'));
    $.SLIDES.initSound('bgSound', $(elementsArray[intSlideCounter]).attr('data-audio_bg'));

    $.SLIDES.active = !$.SLIDES.active;
    $('.' + $.SLIDES.slideWrapperClass).append($.SLIDES.slideCode);

    /*$($.SLIDES.slideSelectorLast).find('.theImg').css({backgroundImage:'url('+currentBgImg+')'});Setto bg*/
    $($.SLIDES.slideSelectorLast).find('.theImg .slideCurrentImage').attr('src', currentBgImg);
    $.SLIDES.initTopMargin();
    /*if(mode != 0){
     $($.SLIDES.slideSelectorLast).addClass('allBottom');
     }*/
    if (mode != 0 && mode != 'back') {
        $($.SLIDES.slideSelectorLast).addClass('allBottom');
        $($.SLIDES.slideSelectorLast).find('.navigation').remove();
    } else if (mode == 'back') {
        $($.SLIDES.slideSelectorLast).addClass('allTop');
        $.COLOR.addColorClass(currentDataColor);

        //reset menu
        $('.thumbs .thumbWrap .singleThumb.current').removeClass('current');
        var tl = new TimelineLite({delay: 0});
        tl.to($('#singleThumb_' + intSlideCounter), .3, {css: {marginTop: '0px'}, ease: Expo.easeOut});
        tl.to($('#singleThumb_' + intSlideCounter), .5, {css: {marginTop: '0px'}, ease: Expo.easeOut});
        //tl.to($('#singleThumb_'+intSlideCounter), .3, {css:{marginTop:(0-($('#singleThumb_'+intSlideCounter).height()-$.SLIDES.thumbUpLimit))+'px'}, ease:Expo.easeOut});
        $('#singleThumb_' + intSlideCounter).addClass('current');

        $($.SLIDES.slideSelectorLast).find('.label').stop().animate({opacity: .5}, 'slow');
        var labCount = $.SLIDES.countSlides() - (parseInt(intSlideCounter) + 1);
        //definisco i valori label e data id nel navigation

        $($.SLIDES.slideSelectorLast).find('.label.current span').html(UTILS.dueCifre(labCount));
        $($.SLIDES.slideSelectorLast).find('.label.current').attr('data-id', parseInt(intSlideCounter));
        labCount = $.SLIDES.countSlides() - (parseInt(intSlideCounter) + 2);
        $($.SLIDES.slideSelectorLast).find('.label.next span').html(UTILS.dueCifre(labCount));
        $($.SLIDES.slideSelectorLast).find('.label.next').attr('data-id', (parseInt(intSlideCounter) + 1));

        TweenLite.to($($.SLIDES.slideSelectorLast).find('.navigation'), 1, {css: {right: '-108px'}, delay: 1.8});


    } else {
    }


    TweenLite.to($($.SLIDES.slideSelectorLast), 1, {css: {left: "0%", top: "0%"}, onComplete: $.SLIDES.killLastSlide});
    $.SLIDES.mostraCaption(intSlideCounter);
    $.SLIDES.currentSlideCounter = intSlideCounter;


}

$.SLIDES.goShortcut = function () {

    //read url params
    var gettedParam = UTILS.getURLParameter(1);
    if (gettedParam != null && gettedParam != undefined && gettedParam != "" && $.SLIDES.paramNav) {
        $.SLIDES.paramNav = false;
        $('li[goto="' + gettedParam + '"]').delay(1000).trigger('click');
    }


}


$.SLIDES.gotoHome = function (mode) {
    if (mode == 'back') {
        $.SLIDES.init();
        $.SLIDES.currentSlideCounter = 0;
        $.SLIDES.createTimer($.SLIDES.maxMillisecondi);
        //$.SLIDES.newSlide(0);
        $.SLIDES.newSlideHome(0, mode);
        $.SLIDES.showThumbs();
        $('#atari,#atariArea').removeClass('home').addClass('slides');
        $('body').removeClass('home');
        $('nav').slideUp('slow');
        $.SLIDES.active == true;
        console.log('back to slides');
        $.SLIDES.resizeThumbs();
        TweenLite.to($('.subSection'), 3, {css: {opacity: 0}, ease: Expo.easeOut});
    } else {
        $.SLIDES.killTimer();
        $.SLIDES.newSlideHome(10, mode);
        $.SLIDES.hideThumbs();
        $.SLIDES.changeLogoToWhite();
        $('#atari,#atariArea').addClass('home').removeClass('slides');
        $.HOMESTICK.init();
        $('body').addClass('home');
        $('nav').slideDown('slow', function () {
        });
        $.COLOR.addColorClass('colorHome');
        console.log('to home');
    }
}
$('.slideshow-txt-close').click(function () {
    $('.slideshow-txt').hide();
    return false;
});
$.SLIDES.openPreloader = function () {
    //$('#preload').css({display:'block'});
    TweenLite.to($('#preload'), .5, {css: {width: '100%'}, ease: Expo.easeOut});
}
$.SLIDES.closePreloader = function () {
    //$('#preload').css({display:'none'});
    TweenLite.to($('#preload'), .5, {css: {width: '0%'}, ease: Expo.easeOut});
}

$.SLIDES.hideThumbs = function () {
    $('.thumbs').animate({top: '-350px'}, 500, function () {
        $(this).slideUp('fast');
    });
}
$.SLIDES.showThumbs = function () {
    $('.thumbs').animate({top: '66px'}, 500, function () {
        $(this).slideDown('slow');
    });
}

$.SLIDES.hideLogo = function (callBackMe) {
    $('header').stop().animate({opacity: 0}, 500, callBackMe);
}
$.SLIDES.showLogo = function (callBackMe) {
    $('header').stop().animate({opacity: 1}, 500, callBackMe);
}

$.SLIDES.changeLogoToWhite = function () {
    /*	$.SLIDES.hideLogo(function(){
     $('header').removeClass('blue');
     $('header').addClass('white');
     $.SLIDES.showLogo(function(){});
     });*/
}
$.SLIDES.changeLogoToOrange = function () {
    /*$.SLIDES.hideLogo(function(){
     $('header').removeClass('blue');
     $('header').removeClass('white');
     $.SLIDES.showLogo(function(){});
     });*/
}
$.SLIDES.changeLogoToBlue = function () {
    /*$.SLIDES.hideLogo(function(){
     $('header').removeClass('white');
     $('header').addClass('blue');
     $.SLIDES.showLogo(function(){});
     });*/
}

//TIMING EVENTS
$.SLIDES.maxMillisecondi = 8000;

$.SLIDES.startTimer = function () {
    if ($.SLIDES.liveTimer) {
        clearInterval($.SLIDES.timer);
        $.SLIDES.timer = setInterval(function () {
            $.SLIDES.initTopMargin();
            $.SLIDES.currentSlideCounter++;
            $.SLIDES.newSlide($.SLIDES.currentSlideCounter);
            $.SLIDES.initTopMargin();
        }, $.SLIDES.maxMillisecondi);
    }
};
$.SLIDES.stopTimer = function () {
    clearInterval($.SLIDES.timer);
};
$.SLIDES.killTimer = function () {
    $.SLIDES.stopTimer();
    $.SLIDES.liveTimer = false;
}
$.SLIDES.createTimer = function (timing) {
    $.SLIDES.maxMillisecondi = timing;
    $.SLIDES.liveTimer = true;
    $.SLIDES.startTimer();
}


//INIT EVENTS
$.SLIDES.loadThumbs();


$.SLIDES.preInit = function () {

    $.SLIDES.closePreloader();

    $('.pics').on("mouseover", ".navigation", function () {
        if ($.SLIDES.navigationActiveHover) {
            if ($.SLIDES.isSlideLoad($(this).find('.next').attr('data-id')) || $.SLIDES.isLast($(this).find('.next').attr('data-id'))) {
                TweenLite.to($(this), 1, {css: {right: '0px'}, ease: Expo.easeOut})
            }
            $.SLIDES.stopTimer();
        }
    });
    $('.pics').on("mouseleave", ".navigation", function () {
        if ($.SLIDES.navigationActiveHover) {
            TweenLite.to($(this), 1, {css: {right: '-108px'}, ease: Expo.easeOut});
            $.SLIDES.startTimer();
        }
    });


    $('.pics').on("mouseover", ".label.next", function () {
        $.HOVERAUDIO.replay();
        TweenLite.to($(this), .5, {css: {opacity: 1}, ease: Expo.easeOut})
    });
    $('.pics').on("mouseleave", ".label.next", function () {
        if ($.SLIDES.navigationActiveHover) {
            TweenLite.to($(this), .5, {css: {opacity: .5}, ease: Expo.easeOut});
        }
    });

    $('.pics').on("click", ".label.next", function () {
        $.SLIDES.newSlide($(this).attr('data-id'));
        $.SLIDES.navigationActiveHover = false;
        TweenLite.to($(".navigation"), .5, {css: {right: '-500px'}, ease: Expo.easeOut, onComplete: function () {
            $(this).parent().remove();
        }});

    });


    $('#atariArea').on("mouseover", function () {
        if ($(this).hasClass('slides')) {
            $.SLIDES.stopTimer();
            //TweenLite.to($('#atari'), 1, {css:{scaleX:0.5, scaleY:0.5}, ease:Elastic.easeInOut});
            if (!$('body').hasClass('explorer')) {
                TweenLite.to($('#atari').find('.stick'), .3, {css: {scaleX: 1.1, scaleY: 1.1, backgroundPosition: '50% 0%'}, ease: Quad.easeInOut});
                TweenLite.to($('#atari').find('.circle'), .1, {css: {opacity: 0}, ease: Quad.easeInOut});
            } else {
                TweenLite.to($('#atari').find('.stick'), .3, {css: {backgroundPosition: '50% 0%'}, ease: Quad.easeInOut});
            }

            $.HOVERAUDIO.replay();
        } else {
            if (!$('body').hasClass('explorer')) {
                //TweenLite.to($('#atari'), 1, {css:{scaleX:0.5, scaleY:0.5}, ease:Elastic.easeInOut});
                TweenLite.to($('#atari').find('.stick'), .3, {css: {scaleX: 1.1, scaleY: 1.1, backgroundPosition: '50% 0%'}, ease: Quad.easeInOut});
                TweenLite.to($('#atari').find('.circle'), .1, {css: {opacity: 0}, ease: Quad.easeInOut});
            } else {
                TweenLite.to($('#atari').find('.stick'), .3, {css: {backgroundPosition: '50% 0%'}, ease: Quad.easeInOut});
            }
        }
    });
    $('#atariArea').on("mouseleave", function () {
        if ($(this).hasClass('slides')) {
            $.SLIDES.startTimer();
            //TweenLite.to($('#atari'), 1, {css:{scaleX:1, scaleY:1}, ease:Elastic.easeInOut});
            if (!$('body').hasClass('explorer')) {
                TweenLite.to($('#atari').find('.stick'), .3, {css: {scaleX: 1, scaleY: 1, backgroundPosition: '50% 100%'}, ease: Quad.easeInOut});
                TweenLite.to($('#atari').find('.circle'), .1, {css: {opacity: 1}, ease: Quad.easeInOut});
            } else {
                TweenLite.to($('#atari').find('.stick'), .3, {css: {backgroundPosition: '50% 100%'}, ease: Quad.easeInOut});
            }

        } else {
            if (!$('body').hasClass('explorer')) {
                //TweenLite.to($('#atari'), 1, {css:{scaleX:1, scaleY:1}, ease:Elastic.easeInOut});
                TweenLite.to($('#atari').find('.stick'), .3, {css: {scaleX: 1, scaleY: 1, backgroundPosition: '50% 100%'}, ease: Quad.easeInOut});
                TweenLite.to($('#atari').find('.circle'), .1, {css: {opacity: 1}, ease: Quad.easeInOut});
            } else {
                TweenLite.to($('#atari').find('.stick'), .3, {css: {backgroundPosition: '50% 100%'}, ease: Quad.easeInOut});
            }
        }
    });
    $('#atariArea').on("click", function () {
        if ($(this).hasClass('slides')) {
            $.SLIDES.gotoHome('back');
        } else {

            $.SLIDES.gotoHome('back');
        }
    });


    //read url params
    var gettedParam = UTILS.getURLParameter(1);
    if (gettedParam != null && gettedParam != undefined && gettedParam != "") {
        $('#atariArea').trigger('click');
    }

}

$.SLIDES.init = function () {

    //SETTO LE CAPTION
    //$.SLIDES.nascondiCaption();
    $.SLIDES.captionResize();

    $.SLIDES.startTimer();


    $.SLIDES.resizeThumbs();


    $($.SLIDES.thumbSelector).each(
        function () {
            $(this).hover(function () {
                /*$.HOVERAUDIO.replay();
                 TweenLite.to($(this), 1, {css:{marginTop:'0px'}, ease:Expo.easeOut});
                 $.SLIDES.stopTimer();*/
            }, function () {
                //$.SLIDES.startTimer();
            });

            $(this).click(function () {
                /*	var currentIndex = $(this).attr('data-id');
                 if($.SLIDES.active){
                 $.SLIDES.newSlide(currentIndex);
                 }*/
            });
        }
    );

    UTILS.getUserAgent();
    if (!UTILS.isDevice) {

        $('.thumbs').on("mouseover", ".singleThumb", function () {
            if (!$(this).hasClass('current')) {
                TweenLite.to($(this).find('figure'), .5, {css: {opacity: '.5'}, ease: Expo.easeOut});
            }

        });

        $('.thumbs').on("mouseout", ".singleThumb", function () {

            TweenLite.to($(this).find('figure'), .5, {css: {opacity: '1'}, ease: Expo.easeOut});

        });

        $('.thumbs').on("click", ".singleThumb", function () {


            var currentIndex = $(this).attr('data-id');
            if ($.SLIDES.active) {
                $.SLIDES.newSlide(currentIndex);
            }

            TweenLite.to($('.thumbs'), .25, {css: {top: '-120px'}, ease: Expo.easeOut});
        });
        $('.thumbs').on("mouseover", function () {
            TweenLite.to($('.thumbs'), .25, {css: {top: '66px'}, ease: Expo.easeOut});
            $.SLIDES.stopTimer();
        });
        $('.thumbs').on("mouseleave", function () {
            TweenLite.to($('.singleThumb').find('figure'), .5, {css: {bopacity: '1'}, ease: Expo.easeOut});
            TweenLite.to($('.thumbs'), .25, {css: {top: '-120px'}, ease: Expo.easeOut});
            $.SLIDES.startTimer();
        });

    } else {


        $('.thumbs').on("click", ".singleThumb img", function () {


            TweenLite.to($('.thumbs'), .25, {css: {top: '-120px'}, ease: Expo.easeOut, onComplete: function () {
                $.SLIDES.startTimer();
            }});

            var currentIndex = $(this).parent().parent().attr('data-id');
            if ($.SLIDES.active) {
                $.SLIDES.newSlide(currentIndex);
            }
        });
        $('.thumbs').on("click", ".timeLine", function () {
            $.SLIDES.stopTimer();
            TweenLite.to($('.thumbs'), .25, {css: {top: '66px'}, ease: Expo.easeOut, onClomplete: function () {
                TweenLite.to($('.thumbs'), .25, {css: {top: '-120px'}, delay: 3, ease: Expo.easeOut, onClomplete: function () {
                    $.SLIDES.startTimer();
                }});
            }});

        });
        $('.thumbs').on("mouseleave", function () {
            TweenLite.to($('.singleThumb').find('figure'), .5, {css: {bopacity: '1'}, ease: Expo.easeOut});
            TweenLite.to($('.thumbs'), .25, {css: {top: '-120px'}, ease: Expo.easeOut});
            $.SLIDES.startTimer();
        });


    }

}


$.SLIDES.moveTimeLine = function ($index) {
    /*
     $('.thumbs .timeLine').css('display','none');
     for(var $i = 0; $i<$index; $i++){
     console.log('timeline till:'+$index+' for .thumbs .singleThumb[id="'+$i+'"] .timeLine');
     $('#singleThumb_'+$i).find('.timeLine').css('display','block');
     }
     */
};


$.SLIDES.initTopMargin = function () {
    $('.pics .singlePic').each(function () {
        var wHeight = $(window).height();
        var wWidth = $(window).width();
        var pHeight = $(this).find('.slideCurrentImage').height();
        var minWidth = 1280;
        var currentImg = $(this).find('.slideCurrentImage').attr('src');

        if (pHeight > wHeight) {

            //$(this).find('.theImg').css({backgroundImage:'url('+currentImg+')'});
            //$(this).find('.slideCurrentImage').css('display','none');
            $(this).find('.slideCurrentImage').css('display', 'block');
            $(this).find('.theImg').css({backgroundImage: 'none'});
            $(this).find('.slideCurrentImage').css('width', '100%');
            $(this).find('.slideCurrentImage').css('height', 'auto');
            //$(this).find('.slideCurrentImage').css('top','-'+Math.round(Math.abs((pHeight-wHeight)/2))+'px');
            //if($('body').hasClass('explorer')){
            //$(this).find('.slideCurrentImage').css('top','-100px');
            //}
        } else {
            if ($('body').is('.resize-b')) {
                $(this).find('.slideCurrentImage').css('display', 'block');
                $(this).find('.theImg').css({backgroundImage: 'none'});
                $(this).find('.slideCurrentImage').css('width', '100%');
                $(this).find('.slideCurrentImage').css('height', 'auto');
            } else {
                $(this).find('.theImg').css({backgroundImage: 'url(' + currentImg + ')'});
                $(this).find('.slideCurrentImage').css('display', 'none');
            }

        }


    });
}

$.SLIDES.initSound = function (soundName, soundPath) {
    if (soundName != null && soundName != "" && soundPath != null && soundPath != "" && SOUNDS.active) {
        soundManager.destroySound(soundName);
        soundManager.createSound({
            id: soundName,
            url: soundPath,
            autoLoad: SOUNDS.autoLoad,
            autoPlay: true,
            loops: 999,
            onload: function () {
            },
            volume: SOUNDS.stdVolume
        });
    } else if (soundName == 'none') {
        soundManager.destroySound(soundName);
    } else if (soundName == 'play' && SOUNDS.active) {
        soundManager.resume(soundName);
    } else if (soundName == 'pause' || !SOUNDS.active) {
        soundManager.pause(soundName);
    }
}

$.SLIDES.captionResize = function () {
    console.log('caption resize:' + $(window).width());
    var winW = $(window).width();
    var winH = $(window).height() - 100;


    if (winW <= 1000) {
        $('.caption:not(.small) img').css('display', 'none');
    } else if (winW <= 1024) {
        $('.caption:not(.small) img').css({'display': 'block', 'width': '240px', 'height': 'auto'});
    } else if (winW <= 1280) {
        $('.caption:not(.small) img').css({'display': 'block', 'width': '340px', 'height': 'auto'});
    } else if (winW <= 1440) {
        $('.caption:not(.small) img').css({'display': 'block', 'width': '440px', 'height': 'auto'});
    } else if (winW <= 1900) {
        $('.caption:not(.small) img').css({'display': 'block', 'width': '540px', 'height': 'auto'});
    }

    if (winH <= 500) {
        $('.caption:not(.small) img').css('display', 'none');
    } else if (winH <= 600) {
        $('.caption:not(.small) img').css({'display': 'block', 'width': '240px', 'height': 'auto'});
    } else if (winH <= 800) {
        $('.caption:not(.small) img').css({'display': 'block', 'width': '340px', 'height': 'auto'});
    } else if (winH <= 900) {
        $('.caption:not(.small) img').css({'display': 'block', 'width': '440px', 'height': 'auto'});
    }

    UTILS.getUserAgent();
    if (UTILS.isDevice) {
        $('.caption:not(.small) img').css({'display': 'block', 'width': '240px', 'height': 'auto'});
    }

    if ($('body').hasClass('explorer')) {
        $('.caption:not(.small) img').css({'display': 'block', 'width': '240px', 'height': 'auto'});
    }


};


$(window).bind('resizeEnd', function () {
    //do something, window hasn't changed size in 500ms
    $.SLIDES.resizeThumbs();
    if (UTILS.getHeight() <= UTILS.minHeight) {
        //$('.pics .caption').slideUp();
    } else {
        //$('.pics .caption').slideDown();
    }
    $.SLIDES.initTopMargin();
    $.SLIDES.captionResize();

    if ($('#ajaxContent.scrollable').size() > 0) {
        window.myNiceScrollObj.resize();
    }
});